{% extends "base.html" %}

{% block title %}{{ canteen.name }} - 详情{% endblock %}

{% block content %}
<div class="detail-container">
    <a href="{{ url_for('index') }}" class="back-link">← 返回首页</a>
    
    <div class="detail-card">
        <h2>{{ canteen.name }}</h2>
        <div class="detail-info">
            <p><strong>位置：</strong>{{ canteen.location }}</p>
            <p><strong>类型：</strong>{{ canteen.type }}</p>
            <p><strong>人均消费：</strong>¥{{ canteen.avg_price }}</p>
            <p><strong>描述：</strong>{{ canteen.description }}</p>
            <div class="rating">
                <strong>评分：</strong>
                {% for i in range(5) %}
                    {% if i < canteen.score|int %}
                        <span class="star filled">★</span>
                    {% else %}
                        <span class="star">★</span>
                    {% endif %}
                {% endfor %}
                {{ canteen.score }}分
            </div>
        </div>
    </div>

    <!-- 评价表单 -->
    {% if session.username %}
    <div class="review-form">
        <h3>发表评价</h3>
        <form method="POST" action="{{ url_for('submit_review') }}">
            <input type="hidden" name="canteen_id" value="{{ canteen.id }}">
            <div class="form-group">
                <label>评分：</label>
                <select name="rating" required>
                    <option value="5">★★★★★ 5分</option>
                    <option value="4">★★★★☆ 4分</option>
                    <option value="3">★★★☆☆ 3分</option>
                    <option value="2">★★☆☆☆ 2分</option>
                    <option value="1">★☆☆☆☆ 1分</option>
                </select>
            </div>
            <div class="form-group">
                <label>评价内容：</label>
                <textarea name="content" rows="4" required placeholder="分享你的用餐体验..."></textarea>
            </div>
            <button type="submit" class="btn">提交评价</button>
        </form>
    </div>
    {% else %}
    <div class="login-prompt">
        <p>请 <a href="{{ url_for('login') }}">登录</a> 后发表评价</p>
    </div>
    {% endif %}

    <!-- 评价列表 -->
    <div class="reviews-section">
        <h3>用户评价 ({{ reviews|length }})</h3>
        {% if reviews %}
            {% for review in reviews %}
            <div class="review-item">
                <div class="review-header">
                    <strong>{{ review.username }}</strong>
                    <span class="review-rating">
                        {% for i in range(5) %}
                            {% if i < review.rating %}
                                <span class="star filled">★</span>
                            {% else %}
                                <span class="star">★</span>
                            {% endif %}
                        {% endfor %}
                    </span>
                </div>
                <p class="review-content">{{ review.content }}</p>
                <small class="review-date">{{ review.created_at[:16] }}</small>
            </div>
            {% endfor %}
        {% else %}
            <p class="no-reviews">暂无评价</p>
        {% endif %}
    </div>
</div>
{% endblock %}